home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Panorama / Panorama - Disk 30B (1988-06-08)(Pacific North-West Amigas Club)[WB].zip / Panorama - Disk 30B (1988-06-08)(Pacific North-West Amigas Club)[WB].adf / DNet1.20 / client / fterm.c next >
C/C++ Source or Header  |  1988-03-22  |  5KB  |  219 lines

  1.  
  2. /*
  3.  *  FTERM.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  FTERM [-Nnet] [port]
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "/include/typedefs.h"
  12. #include "/dnet/channel.h"
  13.  
  14. #include "/server/servers.h"
  15.  
  16. TA Ta = { (ubyte *)"topaz", 8 };
  17.  
  18. ITEXT IText[] = {
  19.     { 0, 1, JAM2, 0, 0, &Ta, (ubyte *)"Flush"          }
  20. };
  21.  
  22. ITEM Item[] = {
  23.     { NULL    , 0, 0, 100, 10, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0, (APTR)&IText[0], NULL, 'o' }
  24. };
  25.  
  26. MENU Menu[] = {
  27.     { NULL    , 0, 0, 100, 20, MENUENABLED, "Control", &Item[0] }
  28. };
  29.  
  30.  
  31. NW Nw = {
  32.     0, 0, 640, 200, -1, -1,
  33.     NEWSIZE|CLOSEWINDOW|MENUPICK,
  34.     WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH|ACTIVATE,
  35.     NULL, NULL, (UBYTE *)"FTERM  Openning, Wait", NULL, NULL,
  36.     32, 32, -1, -1, WBENCHSCREEN
  37. };
  38.  
  39. WIN *Win;
  40.  
  41. int Enable_Abort;
  42. char Buf[512];
  43. char Term[64] = { "FTERM (UNNAMED SHELL)" };
  44. char Cc;
  45.  
  46. extern void *OpenWindow();
  47. extern void *GetMsg();
  48. extern void *CreatePort();
  49.  
  50. long IntuitionBase;
  51. long GfxBase;
  52.  
  53. main(ac,av)
  54. char *av[];
  55. {
  56.     long chan;
  57.     long n;
  58.     long imask, conmask, dmask, mask;
  59.     IOCON *iocr, *iocw;
  60.     char notdone = 1;
  61.     char portspec = 0;
  62.     char *host = NULL;
  63.     uword port = PORT_IALPHATERM;
  64.  
  65.     {
  66.     register short i;
  67.     for (i = 1; i < ac; ++i) {
  68.         if (strncmp(av[i], "-N", 2) == 0) {
  69.         host = av[i] + 2;
  70.         continue;
  71.         }
  72.         portspec = 1;
  73.         port = atoi(av[i]);
  74.     }
  75.     }
  76.     if (portspec)
  77.     printf("Using port %ld\n", port);
  78.     Enable_Abort = 0;
  79.     IntuitionBase = OpenLibrary("intuition.library", 0);
  80.     GfxBase = OpenLibrary("graphics.library", 0);
  81.     Win = OpenWindow(&Nw);
  82.     if (Win == NULL)
  83.     goto e1;
  84.     OpenConsole(Win, &iocr, &iocw);
  85.     if (iocr == NULL || iocw == NULL)
  86.     goto e3;
  87.  
  88.     /*
  89.      *    We delay here to allow DNET to go through its RESTART sequence
  90.      *    (when DNET automatically runs FTERM, it does so to quickly).
  91.      *    Such a hack!
  92.      */
  93.  
  94.     Delay(50 * 4);
  95.     chan = DOpen(host, port, 20, 15);
  96.  
  97.     if (!chan) {
  98.     puts("Unable to connect");
  99.     goto e3;
  100.     }
  101.     DQueue(chan, 32);
  102.     SetMenuStrip(Win, Menu);
  103.     SetWindowTitles(Win, Term, -1);
  104.     imask   = 1 << Win->UserPort->mp_SigBit;
  105.     dmask   = 1 << ((PORT *)chan)->mp_SigBit;
  106.     conmask = 1 << iocr->io_Message.mn_ReplyPort->mp_SigBit;
  107.  
  108.     iocr->io_Data = (APTR)&Cc;
  109.     iocr->io_Length = 1;
  110.     SendIO(iocr);
  111.  
  112.     setsize(iocw, chan);
  113.     while (notdone) {
  114.     mask = Wait(imask|dmask|conmask);
  115.     if (mask & imask) {
  116.         IMESS *im;
  117.         while (im = GetMsg(Win->UserPort)) {
  118.         switch(im->Class) {
  119.         case NEWSIZE:
  120.             setsize(iocw, chan);
  121.             break;
  122.         case CLOSEWINDOW:
  123.             notdone = 0;
  124.             break;
  125.         case MENUPICK:
  126.             switch((uword)((MENUNUM(im->Code)<<8)|ITEMNUM(im->Code))) {
  127.             case 0x0000:    /*    menu 0 item 0    */
  128.             DIoctl(chan, CIO_FLUSH, 0, 0);
  129.             break;
  130.             case 0x0001:    /*    menu 0 item 1    */
  131.             case 0x0002:    /*    menu 0 item 2    */
  132.             case 0x0100:    /*    menu 1 item 0    */
  133.             break;
  134.             }
  135.         }
  136.         ReplyMsg(im);
  137.         }
  138.     }
  139.     if (mask & dmask) {
  140.         char buf[256];
  141.         int n;
  142.         if ((n = DNRead(chan, buf, 256)) > 0) {
  143.         iocw->io_Data = (APTR)buf;
  144.         iocw->io_Length = n;
  145.         DoIO(iocw);
  146.         }
  147.         if (n < 0)
  148.         notdone = 0;
  149.     }
  150.     if (mask & conmask) {
  151.         if (CheckIO(iocr)) {
  152.         WaitIO(iocr);
  153.         DWrite(chan, &Cc, 1);
  154.         iocr->io_Data = (APTR)&Cc;
  155.         iocr->io_Length = 1;
  156.         SendIO(iocr);
  157.         }
  158.     }
  159.     }
  160.     AbortIO(iocr);
  161.     WaitIO(iocr);
  162.     SetWindowTitles(Win, "Closing...", -1);
  163.     DClose(chan);
  164. e3: CloseConsole(iocr,iocw);
  165.     CloseWindow(Win);
  166. e1: CloseLibrary(IntuitionBase);
  167.     CloseLibrary(GfxBase);
  168. }
  169.  
  170. OpenConsole(win, piocr, piocw)
  171. IOCON **piocr, **piocw;
  172. WIN *win;
  173. {
  174.     PORT *port;
  175.     static IOCON iocr, iocw;
  176.     int error;
  177.  
  178.     port = CreatePort(NULL, 0);
  179.     iocr.io_Command = CMD_READ;
  180.     iocr.io_Data = (APTR)win;
  181.     iocr.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  182.     iocr.io_Message.mn_ReplyPort = port;
  183.     error = OpenDevice("console.device", 0, &iocr, 0);
  184.     if (!error) {
  185.     iocw = iocr;
  186.     iocw.io_Command = CMD_WRITE;
  187.     *piocr = &iocr;
  188.     *piocw = &iocw;
  189.     } else {
  190.     *piocr = *piocw = NULL;
  191.     }
  192. }
  193.  
  194. CloseConsole(iocr, iocw)
  195. IOCON *iocr;
  196. IOCON *iocw;
  197. {
  198.     IOCON *tmp = (iocr) ? iocr : iocw;
  199.     if (tmp) {
  200.     CloseDevice(tmp);
  201.     DeletePort(tmp->io_Message.mn_ReplyPort);
  202.     }
  203. }
  204.  
  205. setsize(iocw, chan)
  206. IOCON *iocw;
  207. {
  208.     struct ConUnit *cu = (struct ConUnit *)iocw->io_Unit;
  209.  
  210.     iocw->io_Data = (APTR)"\033c\033[20l\033[t\033[u";
  211.     iocw->io_Length = 13;
  212.     DoIO(iocw);
  213.     DIoctl(chan, CIO_SETROWS, cu->cu_YMax+1, 0);
  214.     DIoctl(chan, CIO_SETCOLS, cu->cu_XMax+1, 0);
  215.     sprintf(Term, "FTERM   %ld x %ld", cu->cu_YMax+1, cu->cu_XMax+1);
  216.     SetWindowTitles(Win, Term, -1);
  217. }
  218.  
  219.